home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000053_icon-group-sender _Fri Feb 28 11:15:31 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Fri, 28 Feb 1997 12:48:10 MST
  2. Date: Fri, 28 Feb 1997 11:15:31 -0600
  3. Message-Id: <199702281715.LAA15028@ns1.cmpu.net>
  4. Mime-Version: 1.0
  5. Content-Type: text/plain
  6. Content-Transfer-Encoding: 7bit
  7. From: gep2@computek.net
  8. Subject: Help with Program
  9. To: icon-group@cs.arizona.edu
  10. X-Mailer: SPRY Mail Version: 04.00.06.17
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12. Status: RO
  13. Content-Length: 1738
  14.  
  15. >Hello.  I am trying to do some text analysis with Icon.  Because I am new
  16. to the language (and to programming in general), I am not sure how to
  17. proceed.
  18.  
  19. >I have a number of texts each line of which has been coded for three types
  20. of information.  Each line of the text will be assigned a number and a
  21. code for two categories. The numbers are just whole numbers (raning from 1
  22. to 20 or so) and each category has four members (say, ABCD and WXYZ). 
  23. Here is an example text: 
  24.  
  25. >1 A X
  26. 1 A Y
  27. 1 B Y
  28. 2 B Y
  29.  
  30. >Note that some successive lines share an index number (as in lines 1 and
  31. 2 and 2 and 3).  When that is the case, I would like the program to
  32. output the members of each category for the matched lines, as below:
  33.  
  34. >1-2    AA    XY
  35.  2-3    AB    YY
  36.  
  37. >Any suggestions?  Thanks in advance.
  38.  
  39. Took me a while to understand what you wanted, but here at least would be a 
  40. SNOBOL4+/SPITBOL version of a complete program that does what you want:
  41.  
  42.     SWS = SPAN(" " CHAR(9))       ;* 'span whitespace' pattern
  43.     TAB = CHAR(9)                 ;* define a tab character
  44.     LET = ANY(&LCASE &UCASE)      ;* parse an alpha character
  45.     RECPAT = SPAN("0123456789") . N SWS LET . M1 SWS LET . M2
  46. RLOOP   (?(N1 = N) ?(M1A = M1) ?(M2A = M2) ?(LN1 = LN)) ;* remember prior line
  47.     LINE = INPUT ?(LN = LN + 1) :F(END)   ;* read and count line
  48.         OUTPUT = ~(LINE ? RECPAT) "Line number " LN " is invalid." :S(RLOOP)
  49.         OUTPUT = EQ(N1,N) LN1 "-" LN TAB M1A M1 TAB M2A M2    :(RLOOP)
  50. END
  51.  
  52. The short length and speed of doing stuff like this in SNOBOL4+/SPITBOL is part 
  53. of what still incites me to do this kind of thing in S-BOL rather than Icon... 
  54. I'll be interested to see what kinds of Icon versions people post!
  55.  
  56. Gordon Peterson
  57. http://www.computek.net/public/gep2/
  58.  
  59.